package com.ruoyi.module.zzy.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YhGasCylinders;
import com.ruoyi.system.service.IYhGasCylindersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 气瓶信息Controller
 * 
 * @author ruoyi
 * @date 2022-11-07
 */
@RestController
@RequestMapping("/zzy/cylinders")
public class ZzyGasCylindersController extends BaseController
{
    @Autowired
    private IYhGasCylindersService yhGasCylindersService;

    /**
     * 查询气瓶信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(YhGasCylinders yhGasCylinders)
    {

        List<YhGasCylinders> list = yhGasCylindersService.selectYhGasCylindersList(yhGasCylinders);
        return getDataTable(list);
    }

    /**
     * 导出气瓶信息列表
     */
    @PreAuthorize("@ss.hasPermi('zzy:cylinders:export')")
    @Log(title = "气瓶信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhGasCylinders yhGasCylinders)
    {
        List<YhGasCylinders> list = yhGasCylindersService.selectYhGasCylindersList(yhGasCylinders);
        ExcelUtil<YhGasCylinders> util = new ExcelUtil<YhGasCylinders>(YhGasCylinders.class);
        util.exportExcel(response, list, "气瓶信息数据");
    }

    /**
     * 获取气瓶信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zzy:cylinders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhGasCylindersService.selectYhGasCylindersById(id));
    }

    /**
     * 新增气瓶信息
     */
    @PreAuthorize("@ss.hasPermi('zzy:cylinders:add')")
    @Log(title = "气瓶信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhGasCylinders yhGasCylinders)
    {
        return toAjax(yhGasCylindersService.insertYhGasCylinders(yhGasCylinders));
    }

    /**
     * 修改气瓶信息
     */
    @PreAuthorize("@ss.hasPermi('system:cylinders:edit')")
    @Log(title = "气瓶信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhGasCylinders yhGasCylinders)
    {
        return toAjax(yhGasCylindersService.updateYhGasCylinders(yhGasCylinders));
    }

    /**
     * 删除气瓶信息
     */
    @PreAuthorize("@ss.hasPermi('zzy:cylinders:remove')")
    @Log(title = "气瓶信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhGasCylindersService.deleteYhGasCylindersByIds(ids));
    }
}
